'''
Created on May 7, 2011

@author: yc30v1m
'''
from library.testresults.Broadcast import Broadcast
from library.AutoLoad import AutoLoad
from logging import getLogger
from library.Utils import singleton


log = getLogger(__name__)

@singleton
class Reporter(Broadcast):
    '''
    classdocs
    '''
    tcid = ""
    tcResult = ""
    tcNotes = ""
    __confReader = ""
    #Fully Qualified Directory for Listners
    __fileFQD = 'library.testresults'
    
    def __init__(self):
        try:
            Broadcast.__init__(self)
            self.__confReader = AutoLoad.ClassAsObject('library.Configuration')
            self.__attachAllResultListners()
        except:
            log.critical("Exception occured Details Below")
            AutoLoad.logExceptionInfo()
        
    def setTestCaseResult(self, tcid, tcResult,tcNotes):
        self.tcid = tcid
        self.tcResult = tcResult
        self.tcNotes = tcNotes
        self.notify()

    def getTestCaseResult(self):
        return self.tcResult
    
    def __attachAllResultListners(self):
        listnerStr = self.__confReader.getOptionFromSection('testcases', 'testresults')
        log.debug('Report Listners are : ' + listnerStr)
        listners = listnerStr.split(",")
        for listnerType in listners:
            try:
                strListner = str(listnerType)
                log.debug("Loading Listner Type :" + strListner)
                setupInfo = self.__confReader.getSection('testcases_' + strListner)
                objListner = AutoLoad.ClassOnly(self.__fileFQD + str(".") + strListner.capitalize())
                self.attach(objListner(setupInfo))
            except:
                log.critical("Report Listner Exception :" + strListner)
                AutoLoad.logExceptionInfo()
        
        